package com.gaohe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gaohe.mapper.CardMapper;
import com.gaohe.pojo.Card;
import com.gaohe.pojo.User;
import com.gaohe.pojo.UserCard;
import com.gaohe.service.CardService;
import com.gaohe.service.UserCardService;
import com.gaohe.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CardServiceImpl extends ServiceImpl<CardMapper, Card> implements CardService {
   @Autowired
   private UserCardService userCardService;
   @Autowired
   private UserService userService;
    @Override
    public List<User> findByCardtoUser(Long id) {
        LambdaQueryWrapper<UserCard> qw = new LambdaQueryWrapper<>();
        qw.eq(UserCard::getCardId,id);
        List<UserCard> list = userCardService.list(qw);
        ArrayList<Long> ids = new ArrayList<>();
        for (UserCard userCard : list) {
            ids.add(userCard.getUserId());
        }
        List<User> users = userService.listByIds(ids);

        return users;
    }
}
